/*
 * Copyright © 2009 Gerald Isaac Schwarz
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package base;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.io.InputStream;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;

public class TextFrame extends JDialog {
	private JEditorPane label = new JEditorPane();
	private StringBuilder stringBuilder = new StringBuilder();
	private InputStream inputStream;
	private GridBagConstraints constraints = new GridBagConstraints();
	
	public TextFrame(String file, String title, String contentType) {
		int ch;
		try {
			this.inputStream = GamePlayer.getInputStream(file);
			while ((ch = this.inputStream.read()) != -1) {
				this.stringBuilder.append((char)ch);
			}
		} catch (Exception e) {
			this.stringBuilder = new StringBuilder();
			this.stringBuilder.append("Failed to load file");
		}
		
		this.label.setContentType(contentType);
		this.label.setEditable(false);
		this.label.setText(this.stringBuilder.toString());
		
		this.getContentPane().setLayout(new GridBagLayout());
		this.constraints.insets = new Insets(5, 5, 5, 5);
		this.constraints.weightx = 1;
		this.constraints.weighty = 1;
		this.constraints.fill = GridBagConstraints.BOTH;
		this.getContentPane().add(this.label, this.constraints);
		
		this.setSize(450, 500);
		this.setLocationByPlatform(true);
		this.setTitle(title);
		this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
	}
}
